﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace ZHDJ.Data.Models.Common
{
    /// <summary>
    /// 积分规则描述
    /// </summary>
    public class PartyObjectScoreRuleDesc : EntityBase
    {
        /// <summary>
        /// 积分规则描述名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string CreateBy { get; set; }

        /// <summary>
        /// 排名名称
        /// </summary>
        public string NoName { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int OrderBy { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public int Status { get; set; }

        #region 查询管理

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="status"></param>
        /// <param name="searchKey"></param>
        /// <returns></returns>
        public static DataSet GetGridData(int pageIndex, int pageSize, string searchKey = "")
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS *,case Status when 4 then '启用' else '禁用' end as  StatusName 
                        from tblPartyObjectScoreRuleDesc 
                        where 1=1 ");
            if (!string.IsNullOrEmpty(searchKey))
            {
                sb.Append(" and Name like ?key ");
                parameters.Add(
                    new MySqlParameter() { DbType = DbType.String, ParameterName = "key", Value = string.Format("%{0}%", searchKey) });
            }

            sb.Append(" order by OrderBy LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
        #endregion

    }
}
